/*
 * GIntCupParticipant.java
 * Created on 13 déc. 2008
 *
 * Glacéo Internet Platform
 * http://sourceforge.net/projects/chm/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hockeo.vhbase.data.helper;

/**
 * Helper class that is used to communicate the clubs that participate in an international
 * contest.
 *
 * @version $Id$
 * @author jjanke
 */
public final class GIntCupParticipant implements Comparable<GIntCupParticipant>
{
  private String  d_strClubId;
  private int     d_nSeeding;
  private double  d_dEcrPoints;
  private boolean d_fTitleDefender;

  /**
   * Creates a new GIntCupParticipant object.
   *
   * @param strClubId the ID of the club participating in an intl. contest
   * @param nSeeding the seeding rank
   * @param dEcrPoints the number of ECR points
   * @param fTitleDefender indicates whether the club has won the intl. cup last year
   */
  public GIntCupParticipant( String strClubId, int nSeeding, double dEcrPoints, boolean fTitleDefender )
  {
    d_strClubId = strClubId;
    d_nSeeding = nSeeding;
    d_dEcrPoints = dEcrPoints;
    d_fTitleDefender = fTitleDefender;
  }

  public String getClubId()
  {
    return d_strClubId;
  }

  public int getSeeding()
  {
    return d_nSeeding;
  }

  public void setSeeding( int nSeeding )
  {
    d_nSeeding = nSeeding;
  }

  public double getEcrPoints()
  {
    return d_dEcrPoints;
  }

  public boolean isTitleDefender()
  {
    return d_fTitleDefender;
  }

  @Override
  public boolean equals( Object obj )
  {
    if ( obj instanceof String )
      return d_strClubId.equals( obj );

    try
    {
      return d_strClubId.equals( ( (GIntCupParticipant) obj ).getClubId() );
    }
    catch ( Exception ex ) // ClassCastException may occur
    {
      return false;
    }
  }

  @Override
  public int hashCode()
  {
    return d_strClubId.hashCode();
  }

  /**
   * Ensure order by ECR points (DESC).
   *
   * @param other the GIntCupParticipant to compare with
   * @return
   */
  public int compareTo( GIntCupParticipant other )
  {
    return Double.compare( other.d_dEcrPoints, this.d_dEcrPoints );
  }
}
